import {getProfileAPI} from '@/api/user'
import {routes} from '@/router/index'
import {resetRouter} from '@/router/index'
export default{
  namespaced:'true',
  state:{
    permission:[],//权限标识
    menuList:[],//路由规则
  },
  mutations:{
    //修改权限标识
    setPermission(state,newPermission){
      state.permission = newPermission
    },
    //修改路由规则
    setMenuList(state,asyncRoutes){
      state.menuList = [...routes,...asyncRoutes]
    },
    //清空路由
    clearMenuList(state){
      state.menuList = []
      resetRouter()
    }
  },
  actions:{
    async getUserPermission(store){
      const res =  await getProfileAPI()
      console.log(res.data,'getProfileAPI')
      store.commit('setPermission',res.data.permissions)
      return res.data.permissions
    },
  }

}